using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace CMS.Web.UI.UserControls
{
    public class RoleEditor : UserControl
    {

        protected Repeater repeaterRole;

        protected TextBox tbRoleName;
        protected Button bValidate;

        public RoleEditor()
        {
            base.Init += new EventHandler(RoleEditor_Init);
        }

        void RoleEditor_Init(object sender, EventArgs e)
        {
            bValidate.Click += new EventHandler(Validate_Click);
            string delete = Request.QueryString["Delete"];
            if (!string.IsNullOrEmpty(delete))
            {
                Roles.DeleteRole(delete);
            }
            BindRole();
        }

        private void BindRole()
        {
            repeaterRole.DataSource = Roles.GetAllRoles();
            repeaterRole.DataBind();
        }

        void Validate_Click(object sender, EventArgs e)
        {
            Roles.CreateRole(tbRoleName.Text);
            BindRole();
        }

    }
}
